package com.jetinno.file

import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView

/**
 * Created by zhangyuncai on 2025/1/7.
 * 描述：监听滑动
 */
class TxtScrollView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : ScrollView(context, attrs) {
    private var mScrollListener: ScrollListener? = null

    fun setScrollListener(scrollListener: ScrollListener?) {
        mScrollListener = scrollListener
    }

    override fun onScrollChanged(horiz: Int, vert: Int, oldHoriz: Int, oldVert: Int) {
        super.onScrollChanged(horiz, vert, oldHoriz, oldVert)
        if (mScrollListener != null) {
            val height = getChildAt(0).height
            val progress = (vert * 100.0f / height).toInt()
            mScrollListener!!.progress(progress)
        }
    }

    interface ScrollListener {
        fun progress(progress: Int)
    }
}
